package org.glut.cloud.repairManage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.glut.cloud.repairManage.entity.SignIn11;
import org.glut.cloud.repairManage.mapper.SignIn11Mapper;
import org.glut.cloud.repairManage.service.ISignIn11Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 签到记录表 服务实现类
 */
@Service
public class SignIn11ServiceImpl extends ServiceImpl<SignIn11Mapper, SignIn11> implements ISignIn11Service {

    @Autowired
    private SignIn11Mapper signIn11Mapper;

    @Override
    public boolean checkSignInStatus() {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        SignIn11 signIn = signIn11Mapper.selectOne(new QueryWrapper<SignIn11>().eq("date", today));
        return signIn != null;
    }

    @Override
    public boolean signIn() {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        if (checkSignInStatus()) {
            return false;
        }
        SignIn11 signIn = new SignIn11();
        signIn.setDate(new Date());
        signIn11Mapper.insert(signIn);
        return true;
    }
}
